# -*- coding: utf-8 -*-
# @Time    : 2021/8/29 23:38
# @Author  : BrandonGT
# @FileName: 04_PyQt5_QWidget_Cursor.py
import sys
from PyQt5.QtWidgets import *
import random

app = QApplication(sys.argv)

# window = QWidget()
# window.resize(500, 500)
#
# current_cursor = window.cursor()
# print(current_cursor.pos())  # 程序运行时 鼠标相对于屏幕的位置
#
# def random_move_cursor():
#     rand_x = random.randint(0, 1920)
#     rand_y = random.randint(0, 1080)
#     print(rand_x, rand_y)
#     current_cursor.setPos(rand_x, rand_y)
#
# btn = QPushButton(window)
# btn.resize(100, 100)
# btn.move(200, 200)
# btn.clicked.connect(random_move_cursor)
#
# window.show()

class myPushButton(QPushButton):
    def __init__(self):
        super().__init__()
        self.x = 0
        self.y = 0

    def mouseMoveEvent(self, mv):
        x = random.randint(0, 500)
        y = random.randint(0, 500)
        self.move(x, y)

class make_fun(QWidget):
    def __init__(self):
        super().__init__()

        rand_x = random.randint(0, 500)
        rand_y = random.randint(0, 500)
        btn = myPushButton()
        btn.setParent(self)
        btn.resize(100, 50)
        btn.setText("点我试试？")
        btn.move(rand_x, rand_y)
        btn.setMouseTracking(True)



window = make_fun()
window.resize(800, 800)
window.setWindowTitle("好玩的东西？")

window.show()
sys.exit(app.exec_())